package com.shenqi.language.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.shenqi.language.domain.Usermark;
import com.shenqi.language.service.IUsermarkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户词条标记Controller
 * 
 * @author shenqi
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/language/usermark")
public class UsermarkController extends BaseController
{
    @Autowired
    private IUsermarkService usermarkService;

    /**
     * 查询用户词条标记列表
     */
    @PreAuthorize("@ss.hasPermi('language:usermark:list')")
    @GetMapping("/list")
    public TableDataInfo list(Usermark usermark)
    {
        startPage();
        List<Usermark> list = usermarkService.selectUsermarkList(usermark);
        return getDataTable(list);
    }

    /**
     * 导出用户词条标记列表
     */
    @PreAuthorize("@ss.hasPermi('language:usermark:export')")
    @Log(title = "用户词条标记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Usermark usermark)
    {
        List<Usermark> list = usermarkService.selectUsermarkList(usermark);
        ExcelUtil<Usermark> util = new ExcelUtil<Usermark>(Usermark.class);
        util.exportExcel(response, list, "用户词条标记数据");
    }

    /**
     * 获取用户词条标记详细信息
     */
    @PreAuthorize("@ss.hasPermi('language:usermark:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(usermarkService.selectUsermarkByUserId(userId));
    }

    /**
     * 新增用户词条标记
     */
    @PreAuthorize("@ss.hasPermi('language:usermark:add')")
    @Log(title = "用户词条标记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Usermark usermark)
    {
        return toAjax(usermarkService.insertUsermark(usermark));
    }

    /**
     * 修改用户词条标记
     */
    @PreAuthorize("@ss.hasPermi('language:usermark:edit')")
    @Log(title = "用户词条标记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Usermark usermark)
    {
        return toAjax(usermarkService.updateUsermark(usermark));
    }

    /**
     * 删除用户词条标记
     */
    @PreAuthorize("@ss.hasPermi('language:usermark:remove')")
    @Log(title = "用户词条标记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(usermarkService.deleteUsermarkByUserIds(ids));
    }


    /**
     * 标记单词
     * @param usermark 单词ID
     * @return
     */
    @PostMapping("/mark")
    public AjaxResult mark(@RequestBody Usermark usermark) {
        Long userId = SecurityUtils.getUserId();
        usermark.setUserId(userId);
        usermarkService.mark(usermark);
        return success();
    }
}
